<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:pe="http://primefaces.org/ui/extensions"
	xmlns:gb="http://giava.by/giavacms/base"
	template="/WEB-INF/layout/t.xhtml">

	<ui:define name="title">
		<h:outputText value="Gestione Pagina" />
	</ui:define>
	<ui:define name="roles">
		<f:attribute name="roles" value="page" />
	</ui:define>
	<ui:define name="content">

		<script type="text/javascript"
			src="#{request.contextPath}/scripts/it_editor.js"></script>

		<script language="javascript" type="text/javascript"
			src="#{request.contextPath}/scripts/tiny_mce/tiny_mce.js"></script>

		<gb:upDown />
		<h:form id="mainForm" prependId="false">

			<p:panel header="Gestione Pagina">

				<h:panelGrid columns="2" style="width: 95%"
					columnClasses="p_col1,p_col2">

					<h:outputLabel value="Titolo(*):" for="titoloW"
						rendered="#{empty pageController.element.title}" />
					<h:inputText required="true" id="titoloW"
						value="#{pageController.element.title}" style="width: 100%;"
						rendered="#{empty pageController.element.id}" />

					<h:outputLabel value="Titolo:" for="titoloR"
						rendered="#{not empty pageController.element.title}" />
					<h:inputText disabled="true" id="titoloR"
						value="#{pageController.element.title}" style="width: 100%;"
						rendered="#{not empty pageController.element.id}" />

					<h:outputLabel value="Descrizione:" for="descrizione" />
					<h:inputText id="descrizione"
						value="#{pageController.element.description}" style="width: 100%;" />

					<h:outputLabel value="Modello(*):" for="template" />
					<h:panelGroup id="template">
						<h:selectOneMenu
							rendered="#{pageController.element.template.template.statico}"
							value="#{pageController.element.template.template.id}"
							required="true" style="width: 100%">
							<f:selectItems value="#{templateStaticiItems}" />
							<p:ajax listener="#{pageController.cambioTemplate}"
								update="campi" />
						</h:selectOneMenu>
						<h:selectOneMenu
							rendered="#{not pageController.element.template.template.statico}"
							value="#{pageController.element.template.template.id}"
							required="true" style="width: 100%">
							<f:selectItems value="#{templateDinamiciItems}" />
							<p:ajax listener="#{pageController.cambioTemplate}"
								update="campi" />
						</h:selectOneMenu>
					</h:panelGroup>

				</h:panelGrid>

				<h:panelGroup id="campi" layout="block">
					<script language="javascript" type="text/javascript">
		tinyMCE
		.init({
			// General options
			mode : "specific_textareas",
			language : "it",
			entity_encoding : "numeric",
			theme : "advanced",
			editor_selector: "tinyMceTa",
			convert_urls : false,
			plugins : "fullscreen,advlink,print,contextmenu,paste,directionality,noneditable,visualchars,nonbreaking,xhtmlxtras,template,table",
			// Theme options
			theme_advanced_buttons1 : "fullscreen,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,fontsizeselect,fontselect,|,hr,|,cut,copy,paste,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,imgBrows,cleanup,|,code",
			theme_advanced_buttons2 : "tablecontrols,|,link,unlink",
			theme_advanced_buttons3 : "",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_fonts : "Arial=Arial;Courier New=Courier New;Times New Roman=Times New Roman;",
			theme_advanced_resizing : true,
			setup : function(ed) {
				<f:verbatim rendered="#{not copertina}">
				// Add a custom button
				ed
						.addButton(
								'imgBrows',
								{
									title : 'Browser immagini',
									image : '#{facesContext.externalContext.request.contextPath}/images/img.gif',
									onclick : function() {
										// Add you own code to execute something on click
										ed.focus();
//										ed.selection.setContent('<div id="imgHere" style="text-align:center;"></div>');
										var popupWindow = window.open('#{request.contextPath}/private/page/imagesTiny.jsf',"Browser immagini","height=600,width=800,modal=yes,alwaysRaised=yes")
										popupWindow.tinyEditor = ed;
									}
								});
				</f:verbatim>
			}
		});
</script>

					<h:panelGrid columns="2" style="width: 95%"
						columnClasses="p_col1,p_col2">

						<h:outputLabel value="Intestazione:"
							rendered="#{not empty pageController.element.template.template.header_stop}"
							for="header" />
						<h:panelGroup
							rendered="#{not empty pageController.element.template.template.header_stop}"
							id="header" layout="block">
							<h:panelGroup style="width: 100%;" layout="block"
								rendered="#{not empty pageController.element.template.template.header_stop and not pageController.element.template.template.statico}">

								<pe:codeMirror id="codeMirror1" theme="eclipse"
									value="#{pageController.element.template.header}"
									readOnly="false" lineNumbers="true" mode="text/html"
									escape="true" />

								<h:inputTextarea
									value="#{pageController.element.template.header}"
									style="color: black; height: 500px; width: 100%;" />
							</h:panelGroup>
							<h:panelGroup style="width: 100%;" layout="block"
								rendered="#{not empty pageController.element.template.template.header_stop and pageController.element.template.template.statico}">
								<h:inputTextarea
									value="#{pageController.element.template.header}"
									id="pEditorC1" styleClass="tinyMceTa"
									style="color: black; height: 500px; width: 100%;" />
							</h:panelGroup>
						</h:panelGroup>

						<h:outputLabel value="Colonna 1:"
							rendered="#{not empty pageController.element.template.template.col1_stop}"
							for="col1" />
						<h:panelGroup style="width: 100%;" id="col1" layout="block"
							rendered="#{not empty pageController.element.template.template.col1_stop}">
							<pe:codeMirror theme="eclipse"
								rendered="#{not empty pageController.element.template.template.col1_stop and not pageController.element.template.template.statico}"
								value="#{pageController.element.template.col1}" readOnly="false"
								lineNumbers="true" mode="text/html" escape="true" />
							<h:inputTextarea
								rendered="#{not empty pageController.element.template.template.col1_stop and not pageController.element.template.template.statico}"
								value="#{pageController.element.template.col1}"
								style="color: black; height: 500px; width: 100%;" />
							<h:panelGroup layout="block"
								rendered="#{not empty pageController.element.template.template.col1_stop and pageController.element.template.template.statico}">
								<h:inputTextarea value="#{pageController.element.template.col1}"
									styleClass="tinyMceTa"
									style="color: black; height: 500px; width: 100%;" />
							</h:panelGroup>
						</h:panelGroup>

						<h:outputLabel value="Colonna 2:"
							rendered="#{not empty pageController.element.template.template.col2_stop}"
							for="col2" />
						<h:panelGroup id="col2" layout="block"
							rendered="#{not empty pageController.element.template.template.col2_stop}">
							<pe:codeMirror theme="eclipse"
								rendered="#{not empty pageController.element.template.template.col2_stop and not pageController.element.template.template.statico}"
								value="#{pageController.element.template.col2}" readOnly="false"
								lineNumbers="true" mode="text/html" escape="true" />
							<h:inputTextarea
								rendered="#{not empty pageController.element.template.template.col2_stop and not pageController.element.template.template.statico}"
								value="#{pageController.element.template.col2}"
								style="color: black; height: 500px; width: 100%;" />
							<h:panelGroup layout="block"
								rendered="#{not empty pageController.element.template.template.col2_stop and pageController.element.template.template.statico}">
								<h:inputTextarea value="#{pageController.element.template.col2}"
									styleClass="tinyMceTa"
									style="color: black; height: 500px; width: 100%;" />
							</h:panelGroup>
						</h:panelGroup>
						<h:outputLabel value="Colonna 3:"
							rendered="#{not empty pageController.element.template.template.col3_stop}"
							for="col3" />
						<h:panelGroup id="col3" layout="block"
							rendered="#{not empty pageController.element.template.template.col3_stop}">
							<pe:codeMirror theme="eclipse"
								rendered="#{not empty pageController.element.template.template.col3_stop and not pageController.element.template.template.statico}"
								value="#{pageController.element.template.col3}" readOnly="false"
								lineNumbers="true" mode="text/html" escape="true" />
							<h:inputTextarea
								rendered="#{not empty pageController.element.template.template.col3_stop and not pageController.element.template.template.statico}"
								value="#{pageController.element.template.col3}"
								style="color: black; height: 500px; width: 100%;" />
							<h:panelGroup layout="block"
								rendered="#{not empty pageController.element.template.template.col3_stop and pageController.element.template.template.statico}">
								<h:inputTextarea value="#{pageController.element.template.col3}"
									styleClass="tinyMceTa"
									style="color: black; height: 500px; width: 100%;" />
							</h:panelGroup>
						</h:panelGroup>

						<h:outputLabel value="Pie' di pagina:"
							rendered="#{not empty pageController.element.template.template.footer_stop}"
							for="footer" />
						<h:panelGroup id="footer" layout="block"
							rendered="#{not empty pageController.element.template.template.footer_stop}">

							<pe:codeMirror theme="eclipse"
								rendered="#{not empty pageController.element.template.template.footer_stop and not pageController.element.template.template.statico}"
								value="#{pageController.element.template.footer}"
								readOnly="false" lineNumbers="true" mode="text/html"
								escape="true" />
							<h:inputTextarea
								rendered="#{not empty pageController.element.template.template.footer_stop and not pageController.element.template.template.statico}"
								value="#{pageController.element.template.footer}" escape="true" />
							<h:panelGroup layout="block"
								rendered="#{not empty pageController.element.template.template.footer_stop and pageController.element.template.template.statico}">
								<h:inputTextarea
									value="#{pageController.element.template.footer}"
									styleClass="tinyMceTa"
									style="color: black; height: 500px; width: 100%;" />
							</h:panelGroup>
						</h:panelGroup>
					</h:panelGrid>

				</h:panelGroup>
				<br />
				<h:outputText value="(*) sono campi obbligatori!" />
				<br />
				<br />

			</p:panel>

			<br />
			<br />

			<center>
				<h:panelGrid columns="1">
					<h:outputLink target="_blank"
						value="#{request.contextPath}/p/#{pageController.element.id}">
						<h:outputText value="anteprima del contenuto gia' salvato" />
					</h:outputLink>
				</h:panelGrid>
				<br />

				<h:panelGrid columns="7">
					<h:commandButton id="ant" value="Anteprima testo completo"
						action="#{pageController.anteprimaTestuale}" rendered="false" />

					<h:commandButton id="save1" value="Salva dati correnti"
						action="#{pageController.salvaPerAnteprimaRisultato}" />

					<h:commandButton id="save2" action="#{pageController.save}"
						value="Salva ed esci"
						rendered="#{empty pageController.element.id}" />

					<h:commandButton id="up1" action="#{pageController.update}"
						value="Salva le modifiche ed esci"
						rendered="#{not empty pageController.element.id}" />

					<h:commandButton id="del1" action="#{pageController.delete}"
						value="Elimina" immediate="true"
						rendered="#{not empty pageController.element.id}"
						onclick="if (!confirm('Vuoi davvero eliminare?')) return false" />

					<h:commandButton id="del2" action="#{pageController.reallyDelete}"
						value="Elimina definitivamente" immediate="true"
						rendered="#{not empty pageController.element.id and loginController.admin}"
						onclick="if (!confirm('Vuoi davvero eliminare definitivamente?')) return false" />

					<h:commandButton id="reset" action="#{pageController.reset}"
						value="Annulla" immediate="true" />
				</h:panelGrid>
			</center>

		</h:form>
	</ui:define>
</ui:composition>